<?php

namespace App\Winged\Tenants;

use Illuminate\Support\Facades\App;
use Illuminate\Support\ServiceProvider;
use League\Flysystem\Exception;

class TenantServiceProvider extends ServiceProvider
{
    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        $this->app->singleton('tenant', function($app) {
            $driver = config('winged.tenants.driver');

            if(!in_array($driver , ['mock','redis'])){
                throw new Exception("tenant driver:{$driver} is not exists") ;
            }
            return TenantReader::getInstance($app)->read($driver);
        });
    }

    public function boot()
    {
    }
}
